package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.success;


/**
 * @author 逗
 */
@RestController
@RequestMapping("/photo")
public class PhotoController {

    @GetMapping(value = "/hsz")
    @Anonymous
    public AjaxResult hsz(){
        List<Map<String, String>> list = new ArrayList<>();

        File filehsz = new File("/home/love/photo/hsz");

        if(filehsz.exists()){
            File[] files = filehsz.listFiles();
            if (files != null) {
                String pathYs = "https://www.ncxdd.com/love/photo/hsz_ys";
                String path = "https://www.ncxdd.com/love/photo/hsz";
                for (File file : files) {
                    Map<String,String> map = new HashMap<>();
                    if (file.isFile()) {
                        map.put("thumbnail", pathYs + "/" + file.getName());
                        map.put("original", path + "/" + file.getName());
                        list.add(map);
                    }
                }
            }
        }
        return success(list);
    }

    @GetMapping(value = "/lyz")
    @Anonymous
    public AjaxResult lyz(){
        List<Map<String, String>> list = new ArrayList<>();

        File filelyz = new File("/home/love/photo/lyz");

        if(filelyz.exists()){
            File[] files = filelyz.listFiles();
            if (files != null) {
                String pathYs = "https://www.ncxdd.com/love/photo/lyz_ys";
                String path = "https://www.ncxdd.com/love/photo/lyz";
                for (File file : files) {
                    Map<String,String> map = new HashMap<>();
                    if (file.isFile()) {
                        map.put("thumbnail", pathYs + "/" + file.getName());
                        map.put("original", path + "/" + file.getName());
                        String url = path + "/" + file.getName();
                        list.add(map);
                    }
                }
            }
        }
        return success(list);
    }

}
